<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <%@ include file="/main/main_css.jsp" %>
    <%@ include file="/main/main_js.jsp" %>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>注册</title>
    <script src="JS/main.js"></script>
  </head>
  
  <body>
	 <div class="all-wrapper">
        <div class="row com-header text-center">
            <span>鹰潭市行政服务中心</span>
        </div>
        <div class="row main-content table-details">
            <div class="row">
            	<div class="col-md-24" >
	                <div class="time-count pull-right">
	                    <span>剩余</span>
	                    <span id="time" class="text-red"></span>
	                    <span>秒</span>
	                </div>
	            </div>
                <div class="col-md-24">
                    <h1>注册</h1>
                </div>
                <div class="row main-content time-table">
                	<table class="table table-bordered time-table-com" style="border:1px solid #efefef;">
                		<tbody>
                			 <tr class="x">
                			 	<td rowspan="3">
                			 		<img width="120px" height="157px" alt="" src="data:image/png;base64,${user.idImg }">
                			 	</td>
                			 	<td>姓名</td>
                			 	<td>${user.realName }</td>
                			 </tr>
                			 <tr class="x">
                			 	<td>性别</td>
                			 	<td>
                			 		<c:if test="${user.sex eq '0' }">
                			 		男
                			 		</c:if>
                			 		<c:if test="${user.sex eq '1' }">
                			 		女
                			 		</c:if>
                			 	</td>
                			 </tr>
                			 <tr class="x">
                			 	<td>身份证号码</td>
                			 	<td>${user.idCard }</td>
                			 </tr>
                			 <tr class="x">
                			 	<td>手机号码：</td>
                			 	<td colspan="2">
                			 		<div class="col-md-10">
	                                    <input id="phone" type="text" class="form-control input-lg">
	                                </div>
	                                <div class="col-md-5">
	                                    <button id="sendMsg" class="btn btn-primary btn-lg" role="button">免费获取验证码</button>
	                                </div>
                			 	</td>
                			 </tr>
                			 <tr class="x">
                			 	<td>请输入验证码：</td>
                			 	<td colspan="2">
                			 		<div class="col-md-15">
	                                    <input id="imeOpen" type="text" class="form-control input-lg">
	                                </div>
                			 	</td>
                			 </tr>
                			 <tr class="x">
                			 	<td>通讯地址：</td>
                			 	<td colspan="2">
                			 		<div class="col-md-15">
	                                    <input id="addr" type="text" class="form-control input-lg">
	                                </div>
                			 	</td>
                			 </tr>
                		</tbody>
                	</table>
                </div>
            </div>
        </div>
        <div class="row footer">
        	<a class="btn btn-success btn-lg" href="index.jsp" role="button"><i class="fa fa-reply"></i>返回首页</a>
            <button id="subForm" class="btn btn-primary btn-lg" role="button">注册<i class="fa fa-hand-pointer-o"></i></button>
        </div>
    </div>
    <form id="registerForm" action="register" method="post">
    	<input type="hidden" id="address" name="address" value="${user.address}">
    	<input type="hidden" id="birthday" name="birthday" value="${user.birthday }">
    	<input type="hidden" id="fpName" name="fpName" value="${user.fpName }">
    	<input type="hidden" id="grantdept" name="grantdept" value="${user.grantdept }">
    	<input type="hidden" id="idCard" name="idCard" value="${user.idCard }">
    	<input type="hidden" id="idImg" name="idImg" value="${user.idImg }">
    	<input type="hidden" id="realName" name="realName" value="${user.realName }">
    	<input type="hidden" id="ethnic" name="ethnic" value="${user.ethnic }">
    	<input type="hidden" id="sex" name="sex" value="${user.sex }">
    	<input type="hidden" id="mPhone" name="phone" value="${user.phone}">
    	<input type="hidden" id="userLifeBegin" name="userLifeBegin" value="${user.userLifeBegin }">
    	<input type="hidden" id="userLifeEnd" name="userLifeEnd" value="${user.userLifeEnd }">
    	<input type="hidden" id="service" name="service" value="${user.service}">
  	</form>
  	<form id="loginOut" action="loginOut"></form>
    <input type="hidden" id="msg">
  	<script>
    	var count = 59;
    	function msgControl(){
    		if (count == 0) { 
    	        $("#sendMsg").attr("disabled",false);
    	        $("#sendMsg").text("免费获取验证码");
    	        countdown = 59; 
    	        return;
    	    } else { 
    	    	$("#sendMsg").attr("disabled", true); 
    	    	$("#sendMsg").text(count + "秒后重新发送"); 
    	        count--; 
    	    }
    		window.setTimeout("msgControl()",1000);
    	}
    	
    	//校验手机号码
    	function checkPhone(phone){
    		var reg = /^1[3|4|5|7|8][0-9]{9}$/;
    		if(reg.test(phone)){
    			return true;
    		}else{
    			return false;
    		}
    	}
    	
    	//绑定打开触摸板接口
    	$("#imeOpen").click(function (){
    		var info = $("#imeOpen").val();
    	    var test = { 'info': info, 'ispassword': 0 };
    	    var data = JSON.stringify(test);
    	    send_command(
    	        "imewrite", data,
    	        function (receivedData) {
    	            var data = JSON.parse(receivedData);
    	            $("#imeOpen").val(data.msg);
    	        }
    	    );
    	});
    	$("#addr").click(function (){
    		var info = $("#addr").val();
    	    var test = { 'info': info, 'ispassword': 0 };
    	    var data = JSON.stringify(test);
    	    send_command(
    	        "imewrite", data,
    	        function (receivedData) {
    	            var data = JSON.parse(receivedData);
    	            $("#addr").val(data.msg);
    	        }
    	    );
    	});
    	$("#phone").click(function (){
    		var info = $("#phone").val();
    	    var test = { 'info': info, 'ispassword': 0 };
    	    var data = JSON.stringify(test);
    	    send_command(
    	        "imewrite", data,
    	        function (receivedData) {
    	            var data = JSON.parse(receivedData);
    	            $("#phone").val(data.msg);
    	        }
    	    );
    	});
    	
    	//绑定发送短信接口
    	$("#sendMsg").click(function (){
    		var phone = $("#phone").val();
    		if(phone == null){
    			layer.alert("请输入手机号码!!!");
    		}else{
    			var flag = checkPhone(phone);
    			if(flag){
    				//点击发送手机号码开始倒计时
    				msgControl();
    				$("#msg").val("");
    				$.ajax({
        				type: 'POST',
        				dataType: 'json',
        				url: "PhoneValiCodeController/getPhoneValiCode",
        				data: {phone:phone},
        				success: function(data){
        					$("#msg").val(data);
        				}
        			});
    			}else{
    				layer.alert("手机号码不正确!!!");
    			}
    		}
    	});
    	
    	//提交表单进行注册
    	$("#subForm").click(function (){
    		var msg = $("#imeOpen").val();
    		var addr = $("#addr").val();
    		if(msg == null || $.trim(msg) == ""){
    			layer.alert("请输入验证码");
    			return;
    		}
    		if(addr == null || $.trim(addr) == ""){
    			layer.alert("请输入通讯地址");
    			return;
    		}
    		if($("#msg").val() == msg){
    			$("#address").val($("#addr").val());
    			$("#mPhone").val($("#phone").val());
    			$("#registerForm").submit();
    		}else{
    			layer.alert("验证码有误,请重新输入!!!");
    		}
    	});
    	
    	var count =  119;
    	function countdown(){
    		$("#time").text(count);
    		if(count > 0){
    			window.setTimeout("countdown()",1000);
    			count --;
    		}else{
    			//跳转到首页
    			$("#loginOut").submit();
    		}
    	}
    	countdown();
    	var winH = $(document).height();
	    var mainH = winH -180;
	    $('.main-content').height(mainH);
    </script>
  </body>
</html>
